//Bounces down on the walls

script_enemy_main{

let GRenemy=("\script\Images\Enemies\Geometric.png");
let SEshotm1=("script\SoundEffects\shotm1.wav");
let SEdeath=("script\SoundEffects\enemydeath1.wav");
let miny=GetClipMinY; let maxy=GetClipMaxY; let minx=GetClipMinX; let maxx=GetClipMaxX;
let cx=GetCenterX; let cy=GetCenterY;
let startx=GetX; let starty=GetY;
let frame=0; let time=0; let animation=0;
let ani=6;
let scale=1;
let shots=0;
let shotcolor=3; let shotspeed=0;
let oldX=0; let oldY=0;
let invincible=125;

let radius=0;
let type=GetArgument[1];

let shot1=0;
let bullet1=[];
let timer1=[];
let angle1=[];

SetAngle(GetArgument[0]);
SetSpeed(3);

@Initialize{
	LoadGraphic("\script\Images\Enemies\Geometric.png");
	LoadSE("script\SoundEffects\shotm1.wav");

	SetInvincibility(40);
	SetLife(15);
	SetDamageRate(10,3); 
	SetScore(1000);
	SetShotColor(255,255,255);
}

@MainLoop{

SetShotAutoDeleteClip(200,200,200,200);

if(GetX<=minx-100 || GetX>=maxx+100 || GetY<=miny-100 || GetY>=maxy+100 && time>=60){ VanishEnemy; }

SetCollisionA(GetX,GetY,32*scale);
SetCollisionB(GetX,GetY,32*scale);


if(GetCommonData("Difficulty")==1){
radius=35;

if(time==0){
let angle=rand(0,360);
	loop(9){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,0);
	Obj_SetSpeed(shot1,0);
	if(type==1){ ObjShot_SetGraphic(shot1,53); }
	if(type==2){ ObjShot_SetGraphic(shot1,49); }
	ObjShot_SetBombResist(shot1,true);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle1=angle1~[shot1];
	angle1[length(bullet1)-1]=angle;
	angle+=360/9;
	}
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); angle1=erase(angle1,i);
	i--;
	}
	else{
	Obj_SetPosition(bullet1[i],GetX+radius*cos(angle1[i]),GetY+radius*sin(angle1[i]));
	timer1[i]=timer1[i]+1;
	angle1[i]=angle1[i]+1;
	}
i++;
}
if(GetY>maxy+80+(radius*2)){ VanishEnemy; }

} //Easy

if(GetCommonData("Difficulty")==2){
radius=40;

if(time==0){
let angle=rand(0,360);
	loop(12){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,0);
	Obj_SetSpeed(shot1,0);
	if(type==1){ ObjShot_SetGraphic(shot1,53); }
	if(type==2){ ObjShot_SetGraphic(shot1,49); }
	ObjShot_SetBombResist(shot1,true);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle1=angle1~[shot1];
	angle1[length(bullet1)-1]=angle;
	angle+=360/12;
	}
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); angle1=erase(angle1,i);
	i--;
	}
	else{
	Obj_SetPosition(bullet1[i],GetX+radius*cos(angle1[i]),GetY+radius*sin(angle1[i]));
	timer1[i]=timer1[i]+1;
	angle1[i]=angle1[i]+1;
	}
i++;
}
if(GetY>maxy+80+(radius*2)){ VanishEnemy; }

} //Normal

if(GetCommonData("Difficulty")==3){
radius=55;

if(time==0){
let angle=rand(0,360);
	loop(15){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,0);
	Obj_SetSpeed(shot1,0);
	if(type==1){ ObjShot_SetGraphic(shot1,53); }
	if(type==2){ ObjShot_SetGraphic(shot1,49); }
	ObjShot_SetBombResist(shot1,true);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle1=angle1~[shot1];
	angle1[length(bullet1)-1]=angle;
	angle+=360/15;
	}
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); angle1=erase(angle1,i);
	i--;
	}
	else{
	Obj_SetPosition(bullet1[i],GetX+radius*cos(angle1[i]),GetY+radius*sin(angle1[i]));
	timer1[i]=timer1[i]+1;
	angle1[i]=angle1[i]+1;
	}
i++;
}
if(GetY>maxy+80+(radius*2)){ VanishEnemy; }

} //Hard

if(GetCommonData("Difficulty")==4){
radius=70;

if(time==0){
let angle=rand(0,360);
	loop(18){
	shot1=(Obj_Create(OBJ_SHOT));
	Obj_SetPosition(shot1,GetX,GetY);
	Obj_SetAngle(shot1,0);
	Obj_SetSpeed(shot1,0);
	if(type==1){ ObjShot_SetGraphic(shot1,53); }
	if(type==2){ ObjShot_SetGraphic(shot1,49); }
	ObjShot_SetBombResist(shot1,true);
	bullet1=bullet1~[shot1];
	timer1=timer1~[shot1];
	timer1[length(bullet1)-1]=0;
	angle1=angle1~[shot1];
	angle1[length(bullet1)-1]=angle;
	angle+=360/18;
	}
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); angle1=erase(angle1,i);
	i--;
	}
	else{
	Obj_SetPosition(bullet1[i],GetX+radius*cos(angle1[i]),GetY+radius*sin(angle1[i]));
	timer1[i]=timer1[i]+1;
	angle1[i]=angle1[i]+1;
	}
i++;
}
if(GetY>maxy+80+(radius*2)){ VanishEnemy; }

} //Lunatic


if(GetX<=minx){
	SetAngle(180-GetAngle);
	SetX(GetX+GetSpeed);
	SetSpeed(3);
}
if(GetX>=maxx){
	SetAngle(180-GetAngle);
	SetX(GetX-GetSpeed);
	SetSpeed(3);
}


oldX=GetX;
oldY=GetY;
frame++;
time++;
animation++;
if(animation>=ani*6){ animation=0; }
if(GetTimeOfInvincibility<25 && invincible>0){ invincible=GetTimeOfInvincibility*5; }

}

@DrawLoop{
	SetGraphicScale(1,1);
	SetTexture(GRenemy);
	SetGraphicAngle(0,0,time*2);
	SetColor(255,255,255);
	SetRenderState(ALPHA);
	if(type==1){ SetGraphicRect(350,200,400,250); }
	if(type==2){ SetGraphicRect(350,0,400,50); }
	DrawGraphic(GetX,GetY);
}

@Finalize{
if(BeVanished==false){
	PlaySE(SEdeath);
	loop(3){ CreateEnemyFromFile("script\Functions\itempower.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0); }
	loop(4){ CreateEnemyFromFile("script\Functions\itempoint.txt",GetX+rand(-40,40),GetY+rand(-40,40),0,0,0); }
#include_function "script/Functions/PlayerTypeBonus.txt";
}

let i=0;
while(i<length(bullet1)){
	if(Obj_BeDeleted(bullet1[i])){
	bullet1=erase(bullet1,i); timer1=erase(timer1,i); angle1=erase(angle1,i);
	i--;
	}
	else{
if(GetCommonData("Difficulty")==1){
	if(BeVanished==false && type==1){ CreateShot02(GetX+radius*cos(angle1[i]),GetY+radius*sin(angle1[i]),0,angle1[i],0.02,2,53,20); }
	if(BeVanished==false && type==2){
		SetShotDirectionType(PLAYER);
		CreateShot02(GetX+radius*cos(angle1[i]),GetY+radius*sin(angle1[i]),0,0,0.02,2,49,20);
		SetShotDirectionType(ABSOLUTE);
	}
} //Easy
if(GetCommonData("Difficulty")==2){
	if(BeVanished==false && type==1){ CreateShot02(GetX+radius*cos(angle1[i]),GetY+radius*sin(angle1[i]),0,angle1[i],0.03,3,53,20); }
	if(BeVanished==false && type==2){
		SetShotDirectionType(PLAYER);
		CreateShot02(GetX+radius*cos(angle1[i]),GetY+radius*sin(angle1[i]),0,0,0.03,3,49,20);
		SetShotDirectionType(ABSOLUTE);
	}
} //Normal
if(GetCommonData("Difficulty")==3){
	if(BeVanished==false && type==1){ CreateShot02(GetX+radius*cos(angle1[i]),GetY+radius*sin(angle1[i]),0,angle1[i],0.04,3.5,53,20); }
	if(BeVanished==false && type==2){
		SetShotDirectionType(PLAYER);
		CreateShot02(GetX+radius*cos(angle1[i]),GetY+radius*sin(angle1[i]),0,0,0.04,3.5,49,20);
		SetShotDirectionType(ABSOLUTE);
	}
} //Hard
if(GetCommonData("Difficulty")==4){
	if(BeVanished==false && type==1){ CreateShot02(GetX+radius*cos(angle1[i]),GetY+radius*sin(angle1[i]),0,angle1[i],0.05,4,53,20); }
	if(BeVanished==false && type==2){
		SetShotDirectionType(PLAYER);
		CreateShot02(GetX+radius*cos(angle1[i]),GetY+radius*sin(angle1[i]),0,0,0.05,4,49,20);
		SetShotDirectionType(ABSOLUTE);
	}
} //Lunatic
	Obj_Delete(bullet1[i]);
	}
i++;
}
}

}